home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16797 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: news.zocalo.net!news
  2. From: Paul Hsieh <qed@xenon.chromatic.com>
  3. Newsgroups: comp.lang.c++,rec.games.programmer,alt.msdos.programmer,comp.programming
  4. Subject: Re: Young programmers read me.
  5. Date: Thu, 11 Apr 1996 20:55:30 -0700
  6. Organization: Zocalo Engineering - Berkeley, California, USA
  7. Message-ID: <316DD432.5B5B@xenon.chromatic.com>
  8. References: <4kj3rp$11d@news1.mnsinc.com> <1557.6675T1105T358@telecall.co.uk>
  9. NNTP-Posting-Host: paulh.chromatic.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. My personal feeling on coding style is that it should reflect what you
  16. are doing.  To that end I try to use the latitude given to me by the
  17. ability to have arbitrary white space in my code to identify "scope".
  18. I think this was the entire intention of K&R when they designed C and
  19. gave their samples.
  20.  
  21. > >: >if(something_happened)
  22. > >: >{
  23. > >: >     do_something_else();
  24. > >: >}
  25. > >: >is_n't_it();   :)
  26.  
  27. The code above is practically unreadable to me, because the lone "{"
  28. confuses me about where the actual scope begins and ends.  Alternatively,
  29.  
  30. if(something) {
  31.     do_something_special();    // The do_something_special function 
  32. } // endif
  33.  
  34. Is_not_what_was_typed_above();    // This is called regardless. 
  35.  
  36. In this way, the beginning and end clause appear more symmetrical and
  37. each line is self describing in what they do.  A single line that says
  38. "{" doesn't describe anything.  It can't be commented beyond saying
  39. "// beginning of scope" which would be really redunant to be looking
  40. at sprinkled all over your code.
  41.  
  42. > >       Sure, I can understand that this might be a problem if you're
  43. > >still using edlin. :)  This is really a personal preference issue and
  44. > >nobody is going to change anyone else's mind.  My problem with the less
  45. > >space argument is that it implies that you don't comment your code either.
  46.  
  47. I'll take the previous poster's personal preference over you *implication*
  48. any day.  I'm a concise but descriptive camper myself.  Code is something
  49. to be written and debugged.  The less time I spend hitting the down arrow
  50. key or the pagedown key and the less time I spent staring at blank white
  51. space that tells me nothing, the better.
  52.  
  53. > >Not to mention the fact that you might as well shove most of your code
  54. > >onto the same lines, only line-breaking when absolutely needed.
  55. > >void foo(int i, char *list){int t;for(t=0;t<i;t++){printf("#%i",t);
  56. > >printf("%s\n",list[t]);}printf("%i total.\n",t);}
  57.  
  58. I would prefer this code to the code above if it were better commented and
  59. used more descriptive tokens.  If you write code in this form though, you
  60. have simply declared that the subtleties of how it works is unimportant and
  61. that you are highly confident of its functionality; its only good for the
  62. global symbol it defines.  Perfectly acceptable, just comment it.
  63.  
  64. > >       Wow!  Look at how much space that saved.  I could put all my code
  65. > >in just two or three pages.  :)  I much prefer.
  66. > There is a neat feature in Amos on the Amiga called "fold", well, really
  67. > it is a feature of the Amos editor, to pack functions or expand them as
  68. > you require.
  69.  
  70. There are utilities for the PC for obfusticating and de-obfusticating your
  71. C-code as well.  AN obfusticator is sitting on the WATCO
  72.  
  73. -- 
  74. Paul Hsieh
  75. qed@xenon.chromatic.com
  76. Graphics Programmer
  77. Chromatic Research
  78.  
  79. What I say and what my company says are not always the same thing
  80.